<?php

namespace app\admin\controller;
use app\admin\validate\LoginForm;
use think\captcha\Captcha;
use think\Controller;
class Login extends Controller
{
    public function login(){

//echo        Pass("1aa4d5a407f4ef741dc6734732dfa8fa6c4880e4");exit;
        if(Request()->isPost()){
            $data = input('post.');
            $validate = new LoginForm();
            if (!$validate->check($data)) {
                return package(20001,$validate->getError());
            }

            $result = $validate->Login($data);
            return package($result['code'],$result['msg'],isset($result['url'])?$result['url']:'');

        }else{
            if(session('admin')){
                $this->redirect('/');
            }
            return view();
        }
    }
    public function verify()
    {
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    30,
            // 验证码位数
            'length'      =>    4,
            // 关闭验证码杂点
            'useNoise'    =>    true,
        ];

        $captcha = new Captcha($config);
        $captcha->codeSet = '0123456789abcdefg';
        return $captcha->entry();
    }

    public function creatList($table,$field){
        return create_listForm($table,$field);
    }
    public function creatForm($table,$title,$type){
        $info = get_db_column_comment($table);
        return view('/common/create_form',['title'=>$title,'info'=>$info,'type'=>$type]);
    }
    public function quit(){
        $info = session('admin'.ADMINTYPE);
        cache($info['token'],null);
        session('admin'.ADMINTYPE,null);
        $this->redirect(url('/login/login'));
    }
}